package com.vision.admin.cl.ui;

import com.sencha.gxt.widget.core.client.Window;
import com.vision.admin.cl.AdminTasks;
import com.vision.admin.company.cl.ui.CreateCompanyWindow;
import com.vision.admin.role.cl.ui.CreateRoleWindow;
import com.vision.admin.user.cl.ui.CreateUserWindow;
import com.vision.core.cl.ui.ITabItemPanelBuilder;
import com.vision.core.cl.ui.MainViewImpl;

/**
 * 
 * @author Mark
 *
 */
public class AdminMainViewImpl extends MainViewImpl {
	
	public AdminMainViewImpl(ITabItemPanelBuilder builder) {
		super(builder);
	}
	
	@Override
	public void openTab(String id) {
		// For the dashboard
		if (id == null || id.isEmpty() || id.equals(AdminDashboardPanel.ID)) {
			super.openTab(AdminDashboardPanel.ID);
			return;
		}
		
		// TODO: Save the window instances so as not to keep creating them  
		if (AdminTasks.ADD_COMPANY.equals(id)) {
			Window w = (Window) new CreateCompanyWindow().asWidget();
			w.show();
			return;
		}
		
		if (AdminTasks.ADD_USER.equals(id)) {
			Window w = (Window) new CreateUserWindow().asWidget();
			w.show();
			return;
		}
		
		if (AdminTasks.ADD_ROLE.equals(id)) {
			Window w = (Window) new CreateRoleWindow().asWidget();
			w.show();
			return; 
		}
		
		super.openTab(id);
	}

}
